﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace BusinessDll
{
    public class LineData
    {
        public Command command { set; get; }
        public Dictionary<String, Object> body { set; get; }
    }
    public enum Command { 
        car,
        rfcar,
        operation
    }
    public enum Operation
    {
        agree,//海关放行
        up,//抬杆
        down,//落杆
        refuse,//海关拒绝
        manuCollect,//补采
        reset,//重置软件
        resetWeight,//重新采集重量
        resetNetwork,//重置网络
        resetDB,//重置地磅
        resetVideo//重置摄像头
    }
    public class CommandBody {
        public Operation command { set; get; }
        public Object body { set; get; }
    }
    public class viewEntity {
        public string time;
        public string module;
        public string info;
        public viewEntity() { 
        }
        public viewEntity(string _time,string _module,string _info) {
            time = _time;
            module = _module;
            info = _info;
        }
    }
    public class CommandList {
        private LinkedList<LineData> line = new LinkedList<LineData>();
        private object lockObject = new object();
        public static Semaphore semaphoreLink = new Semaphore(0,100);
        public bool pushCommandLine(LineData _lineData) {
            bool bRet = true;
            lock (lockObject) { 
                line.AddLast(_lineData);

                //done semaphore+
                semaphoreLink.Release();
            }
            WriteLog.WriteLogs("CommandLine","发出命令"+_lineData.command);
            return bRet;
        }
        public LineData popCommandLine() {
            bool bRet = true;
            LineData lineData = null;
            lock (lockObject)
            {
                lineData = line.First();
                line.RemoveFirst();
                //done semaphore+
            }
            WriteLog.WriteLogs("CommandLine", "消费命令" + lineData.command);
            
            return lineData;
        }

    }
}
